<?php

namespace app\forms\department;

use app\forms\Model;
use app\models\Group;
use app\models\Department;
use app\validators\PositiveInteger;

/**
 * 部门 表单父类
 */
class BaseForm extends Model
{
    public $id;
    public $groupId;
    public $parentId;
    public $type;
    public $name;
    public $sort;

    public function rules()
    {
        return [
            ['groupId', PositiveInteger::class],
            ['groupId', 'required'],
            ['groupId', 'exist', 'targetClass' => Group::class, 'targetAttribute' => 'id'],

            ['parentId', PositiveInteger::class],
            ['parentId', 'default', 'value' => 0],

            ['type', 'integer'],
            ['type', 'required'],
            ['type', 'in', 'range' => array_keys(Department::getTypeMapping())],

            ['name', 'trim'],
            ['name', 'required'],
            ['name', 'string', 'max' => 32],

            ['sort', 'integer'],
            ['sort', 'default', 'value' => 0],
        ];
    }
}